package nbcp.flux.feign

import nbcp.base.extend.*
import nbcp.base.json.*
import nbcp.base.extend.*
import nbcp.base.json.*
import nbcp.base.extend.*
import nbcp.base.json.*
import org.springframework.http.HttpInputMessage
import org.springframework.http.HttpOutputMessage
import org.springframework.http.MediaType
import org.springframework.http.converter.HttpMessageConverter

class NormalTextHttpMessageConverter : HttpMessageConverter<Any> {
    override fun canRead(clazz: Class<*>, mediaType: MediaType): Boolean {
        if (clazz.IsSimpleType()) return true;
        return false;
    }

    override fun canWrite(clazz: Class<*>, mediaType: MediaType?): Boolean {
        if (clazz.IsSimpleType()) return true;
        return false;
    }

    override fun getSupportedMediaTypes(): MutableList<MediaType> {
        return mutableListOf(MediaType.TEXT_PLAIN, MediaType.TEXT_HTML);
    }

    override fun write(t: Any, contentType: MediaType, outputMessage: HttpOutputMessage) {
        throw NotImplementedError()
    }

    override fun read(clazz: Class<out Any>, inputMessage: HttpInputMessage): Any? {
        var ret = inputMessage.body.readContentString()
        return ret.ConvertType(clazz)
    }

}